<template>
  <div class="l-from-body">
    <el-form :model="formData" size="mini" :rules="rules" ref="form" label-width="88px">
      <el-form-item label="模版名称" prop="f_Name">
        <el-input v-model="formData.f_Name" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="模版分类" prop="f_Classify">
        <l-select v-model="formData.f_Classify" placeholder="请选择" :options="schemeTypes"></l-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
const apiSchemeType = window.$api.codetool.schemeType;
const apiScheme = window.$api.codetool.scheme;
export default {
  data() {
    return {
      formData: {
        f_Name: "",
        f_Classify: "",
      },
      rules: {
        f_Name: [{ required: true, message: "请输入模版名称" }],
        f_Classify: [{ required: true, message: "请选择模版分类" }],
      },
      schemeTypes: [],
    };
  },
  methods: {
    async fetchSchemeTypes() {
      const data = await this.$awaitWraper(apiSchemeType.getListProjectId());
      this.schemeTypes = (data || []).map((t) => {
        return { label: t.f_Name, value: t.f_Value };
      });
    },
    resetForm() {
      this.$formClear(this.$refs.form);
    },
    validate() {
      return this.$refs.form.validate();
    },
    async save(content) {
      var postData = {
        f_Name: this.formData.f_Name,
        f_Classify: this.formData.f_Classify,
      };
      postData.f_Content = content;
      postData.f_Type = 1;
      postData.f_ProjectId = this.project.f_Id;

      await apiScheme.addProjectId(postData);
    },
  },
};
</script>
